/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
  StyleSheet,
  Text,
  View,
} from 'react-native';
import {MapView,MapModule,RouteModule} from 'rn-ai-baidu-map'


import Dimensions from 'Dimensions';

export default class TestMap extends Component<{}> {
  constructor(props) {
    super(props);
    this.state = {
      aa: [] //数据
    }
  }

  componentDidMount(){
    MapModule.toPositionAuto().then(
      res => {
        console.log("囧囧有神")
        console.log(res)
      }
    );
  }


  render() {
    return (
      <View style={styles.container}>
        {/* <Text style={styles.welcome}>
          Welcome to React Native!
        </Text> */}
        <MapView
          zoom={14}
          onMapClick={(e)=>
            {
              console.log(e)
              MapModule.setMark(e.latitude,e.longitude).then(
                res => {
                  console.log(res);
                }
              );
            }
          }
         style={styles.map}/>
        <Text onPress={()=>{
          MapModule.toPosition(41.766136,123.444253).then(
            res => console.log(res)
          );
        }} >指定坐标定位</Text>
        <Text onPress={()=>{
          MapModule.toPositionAuto().then(
            res => {
              console.log("囧囧有神")
              console.log(res)
            }
          );
        }} >自动定位</Text>
        <Text onPress={()=>{
          RouteModule.toNavigationSel("hct").then(
            res => {
              console.log(res);
              if(res){
                this.setState({
                  aa:res.Lines
                });
              }
            }
          );
        }} >路线</Text>
        <View ref="t1" style={styles.welcome}>
          {this.state.aa.map((item,i)=>{
            return (<Text onPress={()=>{this.cb(item.index)}} key={item.index}>{item.index}----{item.distance}</Text>)
          })}
        </View>
        <Text ref="t2" onPress={()=>{
          // MapModule.setMark(41.766136,123.444253).then(
          //   res => {
          //     console.log(res);
          //   }
          // );
          
        }} >设置mark</Text>

      </View>
    );
  }
  cb(msg){
    console.log(msg)
    RouteModule.toNavigation("hct",msg);
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  map: {
    width: Dimensions.get('window').width,
    height: Dimensions.get('window').height - 200,
    marginBottom: 16
  }
});
